<template>
  <div>
    <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <el-menu-item index="-1">全部课程</el-menu-item>
      <el-menu-item index="1" @click="open">审核通过</el-menu-item>
      <el-menu-item index="0" @click="open">审核中</el-menu-item>
      <el-menu-item index="2" @click="open">审核失败</el-menu-item>
      <el-button type="primary" @click="handleAdd" plain style="margin-top: 1%">添加课程</el-button>
    </el-menu>
    <div>
      <template>
        <el-table
          :data="tableData"
          style="width: 100%">
          <el-table-column
            prop="cover"
            label="封面"
            width="180">
            <template slot-scope="scope">
            <el-image
              style="width: 100px; height: 100px"
              :src="scope.row.cover"
              fit="contain"></el-image>
            </template>
          </el-table-column>
          <el-table-column
            prop="title"
            label="课程信息"
            width="180">
          </el-table-column>
          <el-table-column
            prop="isFee"
            label="是否免费">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.isFree===0" type="danger">收费</el-tag>
              <el-tag v-if="scope.row.isFree===1" type="success">免费</el-tag>
            </template>
          </el-table-column>
          <el-table-column
            prop="courseOriginal"
            label="价格">
          </el-table-column>
          <el-table-column
            prop="statusId"
            label="状态">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status===0" type="primary">审核中</el-tag>
              <el-tag v-if="scope.row.status===1" type="success">已审核</el-tag>
              <el-tag v-if="scope.row.status===2" type="danger">审核未通过</el-tag>
            </template>
          </el-table-column>
          <!--<el-table-column-->
            <!--prop="putWay"-->
            <!--label="上下架">-->
            <!--<template slot-scope="scope">-->
              <!--&lt;!&ndash;<el-button type="primary" plain :disabled="scope.row.statusId===1 ? false:true">下架</el-button>&ndash;&gt;-->
            <!--</template>-->
          <!--</el-table-column>-->
          <el-table-column label="操作">
            <template slot-scope="scope">
              <!--<router-link :underline="false" :to="{path:'/editCourse',query:{ id: scope.row.id }}">修改</router-link><br>-->
              <router-link :underline="false" :to="{name:'video2', query: {cid:scope.row.cid,isfree:scope.row.isFree}}">章节管理</router-link><br>
              <el-button type="text" v-if="scope.row.status == 2"
                         @click.native.prevent="recheck(scope.row.cid)"
                         size="small">
                重新审核
              </el-button>
              <!--<el-link :underline="false" @click.native.prevent="handleDelete(scope.$index, tableData)">删除</el-link>-->
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
  </div>
</template>

<script>
  import qs from 'qs'
// let courseInfo = [{
//   id:"",
//   cover:"http://meltange.oss-cn-beijing.aliyuncs.com/aaa/123.jpg",
//   title:"从入门到放弃",
//   isFee:"fee",
//   price:"82.5",
//   statusId:"0",
//   putWay:"0"
// }]
export default {
  name: "LuboCourse",
  data() {
    return {
      activeIndex: '-1',
      tableData: [],
      uid:sessionStorage.getItem('uid'),
      tid:'',
    };
  },
  methods: {
    handleSelect(key, keyPath) {
      //console.log(key);
      this.findByTid(this.tid,key);
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, rows) {
      rows.splice(index, 1);
    },
    handleAdd(){
      this.$router.push({
        path:"/addCourse"
      });
    },
    recheck(cid){
      let data = new Object();
      data.status = 0;
      data.cid =cid;
      this.$axios.post("/course/course-audit/audit1",qs.stringify(data)).then(res=>{
         alert(JSON.stringify(res.data));
        if (res.data===true){
          // this.dialogVisible=false;
          // this.queryAll();
          this.findTidByUid(this.uid);
          this.activeIndex =-1;
        }else {
          alert("报错！！！！！！");
        }
      })
    },
    open() {
      // this.$alert('模糊查询同一张表格，显示未审核，已审核，等等', '标题名称', {
      //   confirmButtonText: '确定',
      //   callback: action => {
      //     this.$message({
      //       type: 'info',
      //       message: `action: ${ action }`
      //     });
      //   }
      // });
    },
    findTidByUid(uid){
      this.$axios.post("/showdata/lecturer/findTidByUid/"+uid).then(res=>{
        //console.log(res.data.lecturerId);
        this.tid = res.data[0].lecturerId;
        this.findByTid(this.tid,null);
      }),function () {
        alert("失败!")
      }
    },
    findByTid(tid,status){
      let data = new Object();
      data.LecturerId = tid;
      data.Status = status;
      this.$axios.post("/showdata/eduCourse/findAllByTeacher",qs.stringify(data)).then(res=>{
        console.log(res.data);
        this.tableData = res.data;
      }),function () {
        alert("失败!")
      }
    },
  },
  mounted(){
    this.findTidByUid(this.uid);
  }
}
</script>

<style scoped>

</style>
